#!/usr/bin/env python
#-*- coding: utf-8 -*-

import hashlib

from data.models import *

create_tables(drop=True)

from elixir import session

# Admin user
admin = Admin()
admin.name = u'Federico'
admin.surname = u'Frenguelli'

user = User()
user.username = u'admin'
user.password = hashlib.md5('admin').hexdigest()
user.email = u'info@admin.com'
user.last_modify_date = datetime.datetime.now()
user.subject = admin

session.add(admin)
session.add(user)

# genres
saggio = Genre(name=u'Saggio')
filosofia = Genre(name=u'Filosofia')
politica = Genre(name=u'Politica')
informatica = Genre(name=u'Informatica')
racconto = Genre(name=u'Racconto')
romanzo = Genre(name=u'Romanzo')
italiano = Genre(name=u'Italiano', 
                 description=u'Raccoglie tutti i testi di origine italiana')

# authors
matteo = Author(name=u'Matteo', surname=u'Cossu')
federico = Author(name=u'Federico', surname=u'Frenguelli')
levi = Author(name=u'Carlo', surname=u'Levi')
bassani = Author(name=u'Giorgio', surname=u'Bassani')
bakunin = Author(name=u'Michail Aleksandrovic', surname=u'Bakunin')
atzeni = Author(name=u'Paolo', surname=u'Atzeni')
ceri = Author(name=u'Stefano', surname=u'Ceri')
paraboschi = Author(name=u'Stefano', surname=u'Paraboschi')
torlone = Author(name=u'Riccardo', surname=u'Torlone')

# books
giardino = Book(title=u'Il Giardino dei Finzi-Contini')
giardino.authors.append(bassani)
giardino.genres.append(romanzo)
giardino.genres.append(italiano)
airone = Book(title=u"L'Airone")
airone.authors.append(bassani)
airone.genres.append(racconto)
airone.genres.append(italiano)

stato = Book(title=u'Stato e Anarchia')
stato.authors.append(bakunin)
stato.genres.append(politica)

cristo = Book(title=u'Cristo si è fermato ad Eboli')
cristo.authors.append(levi)
cristo.genres.append(romanzo)
cristo.genres.append(italiano)

peroz = Book(title=u'La Grande Storia del Peroz')
peroz.authors.append(matteo)
peroz.genres.append(racconto)
peroz.genres.append(italiano)

libro_test = Book(title=u'Libro Test 001')
libro_test.authors.append(federico)
libro_test.authors.append(matteo)
libro_test.genres.append(italiano)
libro_test.genres.append(saggio)

#edition
economic = Edition(name=u'Economica')
pocket = Edition(name=u'Pocket')
standard = Edition(name=u'Standard')
deluxe = Edition(name=u'Deluxe')

#product
p_bassani = Product()
p_bassani.name = giardino.title
p_bassani.price = 20.50
p_bassani.edition = deluxe

pb = ProductBooks()
pb.sequence_num = 1
pb.book = giardino
pb.product = p_bassani

#bookshops
libr001 = Bookshop(company_name=u'Libreria Grande')
libr001.addresses.append(Address(address=u'Via Picasso 65', city=u'Perugia'))
libr001.vat = '02055551261'

#order
ord001 = Order()
ord001.bookshop = libr001

session.commit()

